<?php
  $link = mysql_connect('', 'admin_xbq', 'nihao')
      or die('Could not connect: ' . mysql_error());
  echo 'Connected successfully';
  
  if (isset($_GET['db'])) {
    $sql = "use ".$_GET['db'];
    mysql_query($sql);
  }

  if (isset($_GET['tab'])) {
    $sql = "Drop table ". $_GET['tab'].";";
    mysql_query($sql);
  }

  $query = "show tables;";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());

  echo "<div  align=\"center\">";
  echo "<table class=\"style2\"  width=\"250\">\n";
  echo "<tr>\n
        <th>Name of tables</th>
        <th>Delete</th>
        </tr>\n";
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
      echo "\t\t<td><a href=\"showrows.php?tab=".$col_value."\">".$col_value."</a></td>\n";
      echo "\t\t<td align=\"center\" width=\"50\">\n";
      echo "\t\t\t<a href=\""; 
      echo $_SERVER['PHP_SELF'];
      echo "?db=".$_GET['db']."\"><img src=\"img/b_drop.png\" Onclick=\"if(!confirm('Are you sure to delete table?')) return false;\" alt=\"Drop table\" /></a>\n";
      echo "\t\t</td>\n";
    }
    echo "\t</tr>\n";
  }
  echo "</table>\n";
  echo "</div>";
  
  mysql_free_result($result);

  mysql_close($link);
?>
